#include "graph.h"

using namespace std;

typedef Graph<int, 5> GraphAcht;

void displayMenu();
void inputMenu(GraphAcht *graph) throw(BadVertex);

int main(int argc, char *argv[])
{
	GraphAcht g;	
	while(true) {
		try {
			inputMenu(&g);
		}
		catch(BadVertex& err)
		{
			cerr << endl << "Exception : Ecke " << err.getBadIndex() << " wurde nicht gefunden."<< endl;
		}
	}
	return 0;
}
void inputMenu(GraphAcht *graph) throw (BadVertex){
	
	int DFS[9];
	memset(DFS, 0, sizeof(DFS));
	int input;
	int input2;
	int input3;
	int input4;
	
	displayMenu();		
	while(cin>>input) {
		if(input==1) {
			cout << "Bitte Start eingeben : "<<endl;
			cin >> input2;
			cout << "Bitte Ziel eingeben : "<<endl;
			cin >> input3;
			cout << "Bitte Gewicht eingeben : "<<endl;
			cin >> input4;
			graph->insertEdge(input2,input3,input4);
			displayMenu();
		}
		else if(input==2) {
			cout << "depthFirst :" <<endl;
			cout << "Bitte Start eingeben : "<<endl;
			cin >> input2;
			cout << "Bitte Ziel eingeben : "<<endl;
			cin >> input3;
			graph->depthFirst(input2,input3, DFS);
			memset(DFS, 0, sizeof(DFS));
			displayMenu();
		}
		else if(input==3) {
			cout << "breadthFirst :" <<endl;				
			cout << "Bitte Start eingeben : "<<endl;
			cin >> input2;
			cout << "Bitte Ziel eingeben : "<<endl;
			cin >> input3;
			graph->breadthFirst(input2,input3);
			displayMenu();
			
		}
		else if(input==4) {
			cout << "Dijkstra :" <<endl;							
			cout << "Bitte Start eingeben : "<<endl;
			cin >> input2;
			cout << "Bitte Ziel eingeben : "<<endl;
			cin >> input3;
			graph->dijkstra(input2,input3);
			displayMenu();
		}
		else if(input==5) {
			cout << "Adjacence test :" <<endl;					
			cout << "Bitte Start eingeben : "<<endl;
			cin >> input2;
			cout << "Bitte Ziel eingeben : "<<endl;
			cin >> input3;
			cout << endl << input2 << " und " << input3 << " sind ";
			if(!graph->adjacent(input2,input3)) cout << "nicht ";
			cout << "verbunden !!"  << endl;
			displayMenu();
			
		}
		else if(input==6) {
			graph->display();
			displayMenu();
		}
		else if(input==7){
			cout << "Programm schliessen." << endl;
			exit(0);
		}
		else {
			cout << " Unbekannte Eingabe " << endl;
			displayMenu();
		}
	}
}

void displayMenu() {
	cout << endl;
	cout << "Graph Menu"<<endl;
	cout << "-----------"<<endl;
	cout << "(1) Kante einfuegen"<<endl;
	cout << "(2) depthFirst"<<endl;
	cout << "(3) breadthFirst"<<endl;
	cout << "(4) Dijkstra"<<endl;
	cout << "(5) Adjacence"<<endl;
	cout << "(6) Graph anzeigen"<<endl;
	cout << "(7) Exit" <<endl;
	cout << endl;
	cout << "Ihre Wahl:" <<endl;
}